package cn.lopr.hfbdqn.util.jwt;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;

import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;

public class ParseJwtTest {
    public static void main(String[] args) {
        String token = "eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiI0Iiwic3ViIjoiMTgyNTU0MzE4ODEiLCJpYXQiOjE2MjA5NjEzMDgsInJvbGVzIjoidXNlciIsIm90aGVyIjpbeyJpZCI6NCwicGhvbmUiOiIxODI1NTQzMTg4MSIsInBhc3N3b3JkIjpudWxsLCJuaWNrbmFtZSI6ImMyMyIsInNleCI6IueUtyIsImJpcnRoZGF5IjoiMTk5OS0wMS0wMSIsInBvcnRyYWl0IjoiaHR0cHM6Ly9pbS0xMjU2MjE4MjIxLmNvcy5hcC1uYW5qaW5nLm15cWNsb3VkLmNvbS9wb3J0cmFpdC9kZWZhdWx0NC5wbmciLCJpbnRyb2R1Y3Rpb24iOiLnroDku4vplb_kuIDngrkifV0sImV4cCI6MTYyMDk2NDkwOH0.Thkr1R2RuGPsj1euwsIfvIavIY5EoUz3pYJeBNQWhsE";
        SecretKey key = new SecretKeySpec("cn.lopr.im.api".getBytes(), "AES");
        Claims claims = Jwts.parser().setSigningKey(key).parseClaimsJws(token).getBody();
        System.out.println("id:" + claims.getId());
        System.out.println("subject:" + claims.getSubject());
        System.out.println("IssuedAt:" + claims.getIssuedAt());
        ObjectMapper objectMapper = new ObjectMapper();
        System.out.println("IssuedAt:" + claims.get("other"));
        System.out.println("IssuedAt:" + claims.get("role"));
    }
}